<?php /* Smarty version Smarty3-RC3, created on 2013-10-11 09:26:41
         compiled from ".\templates\vepaariBookAavak.tpl" */ ?>
<?php /*%%SmartyHeaderCode:193675257c451d4a972-66074590%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_smarty_tpl->decodeProperties(array (
  'file_dependency' => 
  array (
    'ddfb51959611e41330f270224c448371b299fd62' => 
    array (
      0 => '.\\templates\\vepaariBookAavak.tpl',
      1 => 1379654924,
    ),
  ),
  'nocache_hash' => '193675257c451d4a972-66074590',
  'function' => 
  array (
  ),
  'has_nocache_code' => false,
)); /*/%%SmartyHeaderCode%%*/?>
<?php if (!is_callable('smarty_function_html_options')) include 'D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\sil1\include\Smarty\libs\plugins\function.html_options.php';
if (!is_callable('smarty_function_html_select_date')) include 'D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\sil1\include\Smarty\libs\plugins\function.html_select_date.php';
?><?php $_template = new Smarty_Internal_Template("header.tpl", $_smarty_tpl->smarty, $_smarty_tpl, $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, null, null);
 echo $_template->getRenderedTemplate();?><?php $_template->updateParentVariables(0);?><?php unset($_template);?>
<script type="text/javascript" src="./js/jquery.js"></script>
<script type="text/javascript">
var prevPartyFine = 0;
var prevPartyAmount = 0;
rowNumber = 1;	
$(document).ready(function()
{
  $(".delete").live('click', function(event) 
  {
    $(this).parent().remove();
     totFine(this);
     totFineFuncedit(this);
     setAmount(this);
  });
});

function addNewRow()
{
  $('#billBook tr:last').after('<tr class="itemRow"><?php if ($_smarty_tpl->getVariable('billBookArr')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['rojmelId']!=0){?><td><input type="checkbox" name="rojmelEntry['+rowNumber+']"  checked /></td><?php }else{ ?><td><input type="checkbox" name="rojmelEntry['+rowNumber+']" /></td><?php }?><td><input type="text" name="particulars[]" \/><\/td><\/td><td><input type="text" name="netWeight[]" class="netWeight" \/><\/td><td><input type="text" name="touch[]" class="touch" onChange="setFine(this)"\/><\/td><td><input type="text" name="waste[]" class="waste" onChange="setFine(this)"\/><\/td><td><input type="text" name="fine[]" class="fine" onChange="totFine()"\/><\/td><td><input type="text" name="qty[]" class="qty" onChange="setAmount(this)"\/><\/td><td><input type="text" name="labour[]" class="labour" onChange="setAmount(this)"\/><\/td><td><input type="text" name="amount[]" class="amount" \/><\/td><td><a href="javascript:addNewRow();"><?php echo $_smarty_tpl->getVariable('l_add')->value;?>
<\/a><\/td><td class="delete"><?php echo $_smarty_tpl->getVariable('l_remove')->value;?>
<\/td><\/tr>');
  rowNumber++;
}

function setTotNetWeight()
{
  var totalNetWeight = 0;
  
  $('.netWeight').each(function(i)
  {
    price = $(this).val().replace("$","");
    if (!isNaN(price)) totalNetWeight += Number(price);
  });

  $('#totWeight').val(totalWeight);
  $('#totPari').val(totalpari);
  $('#totNetWeight').val(totalNetWeight);
}

function setFine(txtObj)
{
  var row = $(txtObj).parents('.itemRow');
  var price = (parseFloat(row.find('.netWeight').val()) * (parseFloat(row.find('.touch').val().replace("$","")) + parseFloat(row.find('.waste').val())) / 100);
  isNaN(price) ? row.find('.fine').val("") : row.find('.fine').val(price);
  totFine();
}

function totFine()
{
  var totFine = 0;
  
  $('.fine').each(function(i)
  {
    price = $(this).val().replace("$","");
    if (!isNaN(price)) totFine += Number(price);
  });
  
  $('#totFine').val(totFine);
  $('#partyFine').val(parseFloat(prevPartyFine) - parseFloat(totFine));
   totFineFuncedit()
}

function totFineFuncedit()
{
   var totFine = 0;
  
  $('.fine').each(function(i)
  {
    price = $(this).val().replace("$","");
    if (!isNaN(price)) totFine += Number(price);
  });
  $('#totFine').val(totFine);
  prevFineLess = $("#prevFineWithoutThisBill").val();
  $('#partyFineEdit').val(parseFloat(prevFineLess) - parseFloat(totFine));
}

function setAmount(txtObj)
{
  var row = $(txtObj).parents('.itemRow');
  var price = parseFloat(row.find('.qty').val().replace("$","")) * parseFloat(row.find('.labour').val());
  isNaN(price) ? row.find('.amount').val("") : row.find('.amount').val(price);
  setTotAmount();
}

function setTotAmount()
{
  var totQty    = 0;
  var totLabour = 0;
  var totAmount = 0;
  
  $('.amount').each(function(i)
  {
    price = $(this).val().replace("$","");
    if (!isNaN(price)) totAmount += Number(price);
  });
  $('#totAmount').val(totAmount);
  $('#partyAmount').val(parseFloat(prevPartyAmount) - parseFloat(totAmount));
  
  $('.labour').each(function(i)
  {
    price = $(this).val().replace("$","");
    if (!isNaN(price)) totLabour += Number(price);
  });
  $('#totLabour').val(totLabour);
  
  $('.qty').each(function(i)
  {
    price = $(this).val().replace("$","");
    if (!isNaN(price)) totQty += Number(price);
  });
  $('#totQty').val(totQty);
  setTotAmountEdit();
}

function setTotAmountEdit()
{
  var totQty    = 0;
  var totLabour = 0;
  var totAmount = 0;
  
  $('.amount').each(function(i)
  {
    price = $(this).val().replace("$","");
    if (!isNaN(price)) totAmount += Number(price);
  });
  prevAmountLess = $("#prevAmountWithoutThisBill").val();
  $('#totAmount').val(totAmount);
  $('#partyAmountEdit').val(parseFloat(prevAmountLess) - parseFloat(totAmount));
}
  function getOldAmount()
  {
	if(document.form1.party.value > 0)
	{
      $.ajax({
	    type:"POST",
	    url:'getOldAmountVepaari.php',
	    data:
	    {
	      partyId : document.form1.party.value
	    },
	    success: function(response)
	    {
	    	var temp = response.split(",");
	    	prevPartyFine = temp[0];
	    	prevPartyAmount = temp[1];
	    	$('#partyFine').val(prevPartyFine);
	    	$('#partyAmount').val(prevPartyAmount);
	    }
    });
	}
}

function hidePrevDiv(chkObj)
{
	if(chkObj.checked)
	  $('#oldTotal').show();
	else
	  $('#oldTotal').hide();
}
</script>
<form name="form1" action="" method="post">
<input type="hidden" name="isEdit" value="<?php echo $_smarty_tpl->getVariable('isEdit')->value;?>
" />
<input type="hidden" name="prevFineWithoutThisBill" id="prevFineWithoutThisBill" value="<?php echo $_smarty_tpl->getVariable('prevFineWithoutThisBill')->value;?>
" />
<input type="hidden" name="prevAmountWithoutThisBill" id="prevAmountWithoutThisBill" value="<?php echo $_smarty_tpl->getVariable('prevAmountWithoutThisBill')->value;?>
" />
<center><h4>Aavak Entry</h4></center>
<?php if ($_smarty_tpl->getVariable('msg')->value!=''){?><center><span style="color:#FF0000"><b><?php echo $_smarty_tpl->getVariable('msg')->value;?>
</b></span></center><?php }?>
<div class="contentDiv">
  <table border="0" id="billBook" align="center" width="100%">
  <tr>
    <td colspan="5" class="table1">
      <?php echo $_smarty_tpl->getVariable('l_partySelect')->value;?>
 :
      <select name="party" onChange="getOldAmount();">
        <?php echo smarty_function_html_options(array('values'=>$_smarty_tpl->getVariable('party')->value['partyId'],'output'=>$_smarty_tpl->getVariable('party')->value['partyName'],'selected'=>$_smarty_tpl->getVariable('partyId')->value),$_smarty_tpl->smarty,$_smarty_tpl);?>

      </select>
    </td>
    <td colspan="6" class="table1">
      <?php echo $_smarty_tpl->getVariable('l_billBookDate')->value;?>
 : 
      <?php echo smarty_function_html_select_date(array('prefix'=>"curDate",'start_year'=>"-2",'end_year'=>"+1",'field_order'=>"DMY",'day_value_format'=>"%02d",'time'=>$_smarty_tpl->getVariable('billDate')->value),$_smarty_tpl->smarty,$_smarty_tpl);?>

    </td>
    <td class="table1"><input type="checkbox" name="removePrev" onChange="hidePrevDiv(this);" CHECKED /></td>
  </tr>
  <tr class="table1">
  	<th>&nbsp;</th>
    <th><?php echo $_smarty_tpl->getVariable('l_particulars')->value;?>
</th>
    <th><?php echo $_smarty_tpl->getVariable('l_netWeight')->value;?>
</th>
    <th><?php echo $_smarty_tpl->getVariable('l_touch')->value;?>
</th>
    <th><?php echo $_smarty_tpl->getVariable('l_waste')->value;?>
</th>
    <th><?php echo $_smarty_tpl->getVariable('l_fine')->value;?>
</th>
    <th><?php echo $_smarty_tpl->getVariable('l_qty')->value;?>
</th>
    <th><?php echo $_smarty_tpl->getVariable('l_labour')->value;?>
</th>
    <th><?php echo $_smarty_tpl->getVariable('l_amount')->value;?>
</th>
    <th colspan="2">&nbsp;</th>
  </tr>
  <?php if ($_smarty_tpl->getVariable('isEdit')->value==1){?>
    <?php unset($_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]);
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['name'] = "sec";
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['loop'] = is_array($_loop=count($_smarty_tpl->getVariable('billBookArr')->value)) ? count($_loop) : max(0, (int)$_loop); unset($_loop);
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['show'] = true;
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['max'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['loop'];
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['step'] = 1;
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['start'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['step'] > 0 ? 0 : $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['loop']-1;
if ($_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['show']) {
    $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['total'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['loop'];
    if ($_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['total'] == 0)
        $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['show'] = false;
} else
    $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['total'] = 0;
if ($_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['show']):

            for ($_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['index'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['start'], $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['iteration'] = 1;
                 $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['iteration'] <= $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['total'];
                 $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['index'] += $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['step'], $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['iteration']++):
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['rownum'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['iteration'];
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['index_prev'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['index'] - $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['step'];
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['index_next'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['index'] + $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['step'];
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['first']      = ($_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['iteration'] == 1);
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['last']       = ($_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['iteration'] == $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['total']);
?>
      <tr class="itemRow">
      <?php if ($_smarty_tpl->getVariable('billBookArr')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['rojmelId']!=0){?>
        <td><input type="checkbox" name="rojmelEntry[<?php echo $_smarty_tpl->getVariable('smarty')->value['section']['sec']['index'];?>
]" value= "1" checked /></td>
      <?php }else{ ?>
        <td><input type="checkbox" name="rojmelEntry[<?php echo $_smarty_tpl->getVariable('smarty')->value['section']['sec']['index'];?>
]" value= "1" /></td>
      <?php }?>
        <td><input type="text" name="particulars[]" value="<?php echo $_smarty_tpl->getVariable('billBookArr')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['particulars'];?>
" /></td>
        <td><input type="text" name="netWeight[]" class="netWeight" onChange="setNetWeight(this)" value="<?php echo $_smarty_tpl->getVariable('billBookArr')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['netWeight'];?>
" /></td>
        <td><input type="text" name="touch[]" class="touch" onChange="setFine(this)" value="<?php echo $_smarty_tpl->getVariable('billBookArr')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['touch'];?>
" /></td>
        <td><input type="text" name="waste[]" class="waste" onChange="setFine(this)" value="<?php echo $_smarty_tpl->getVariable('billBookArr')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['waste'];?>
" /></td>
        <td><input type="text" name="fine[]" class="fine" onChange="totFine()" value="<?php echo $_smarty_tpl->getVariable('billBookArr')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['fine'];?>
" /></td>
        <td><input type="text" name="qty[]" class="qty" onChange="setAmount(this)" value="<?php echo $_smarty_tpl->getVariable('billBookArr')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['qty'];?>
" /></td>
        <td><input type="text" name="labour[]" class="labour" onChange="setAmount(this)" value="<?php echo $_smarty_tpl->getVariable('billBookArr')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['labour'];?>
" /></td>
        <td><input type="text" name="amount[]" class="amount" value="<?php echo $_smarty_tpl->getVariable('billBookArr')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['amount'];?>
" /></td>
        <td><a href="javascript:addNewRow();"><?php echo $_smarty_tpl->getVariable('l_add')->value;?>
</a></td>
        <td class="delete"><?php echo $_smarty_tpl->getVariable('l_remove')->value;?>
</td>
      </tr>
    <?php endfor; endif; ?>
  <?php }?>
  <tr class="itemRow">
  	<td><input type="checkbox" name="rojmelEntry[]" value= "1" /></td>
    <td><input type="text" name="particulars[]" title="amount"/></td>
    <td><input type="text" name="netWeight[]" class="netWeight" onChange="setNetWeight(this)" title="amount"/></td>
    <td><input type="text" name="touch[]" class="touch" onChange="setFine(this)"/></td>
    <td><input type="text" name="waste[]" class="waste" onChange="setFine(this)"/></td>
    <td><input type="text" name="fine[]" class="fine" onChange="totFine()"/></td>
    <td><input type="text" name="qty[]" class="qty" onChange="setAmount(this)"/></td>
    <td><input type="text" name="labour[]" class="labour" onChange="setAmount(this)"/></td>
    <td><input type="text" name="amount[]" class="amount" onChange="setTotAmount()"/></td>
    <td><a href="javascript:addNewRow();"><?php echo $_smarty_tpl->getVariable('l_add')->value;?>
</a></td>
    <td class="delete"><?php echo $_smarty_tpl->getVariable('l_remove')->value;?>
</td>
    <td>&nbsp;</td>
  </tr>
  </table>
  <table width="100%">
    <tr class="itemRowTot">
      <th align="right" width="105px;"><?php echo $_smarty_tpl->getVariable('l_total')->value;?>
</th>
      <th align="right" width="105px;">&nbsp;</th>
      <th align="right" width="105px;">&nbsp;</th>
      <th align="right" width="105px;">&nbsp;</th>
      <th align="right" width="105px;">&nbsp;</th>
      <th><input type="text" name="totFine" id="totFine"/></th>
      <th><input type="text" name="totQty" id="totQty"/></th>
      <th><input type="text" name="totLabour" id="totLabour"/></th>
      <th><input type="text" name="totAmount" id="totAmount"/></th>
      <th colspan="2" width="70px;"></th>
    </tr>
  </table>
 <?php if ($_smarty_tpl->getVariable('isEdit')->value==1){?>
   <div id="oldTotal" style="float:right;">
     <b>Prev. Fine</b> <input type="text" name="partyFine" id="partyFine" value=<?php echo $_smarty_tpl->getVariable('prevFine')->value;?>
 />
  	 <b>Prev. Amount</b> <input type='text' name='partyAmount' id='partyAmount' value=<?php echo $_smarty_tpl->getVariable('prevAmount')->value;?>
 />
  </div>
   <?php }else{ ?>
  <div id="oldTotal" style="float:right;">
  	<b>Prev. Fine</b> <input type="text" name="partyFine" id="partyFine" />
  	<b>Prev. Amount</b> <input type='text' name='partyAmount' id='partyAmount' />
  </div>
  <?php }?>
  <?php if ($_smarty_tpl->getVariable('isEdit')->value==1){?>
    <input type="submit" name="billBookAddBtn" value="<?php echo $_smarty_tpl->getVariable('l_save')->value;?>
"/>
  <?php }else{ ?>
    <input type="submit" name="billBookAddBtn" value="<?php echo $_smarty_tpl->getVariable('l_addBillBook')->value;?>
"/>
  <?php }?>
</div>
</form>
<script type="text/javascript">
<?php if ($_smarty_tpl->getVariable('isEdit')->value==1){?>
  setTotNetWeight();
  totFine();
  setTotAmount();
<?php }?>  
</script>
<?php $_template = new Smarty_Internal_Template("footer.tpl", $_smarty_tpl->smarty, $_smarty_tpl, $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, null, null);
 echo $_template->getRenderedTemplate();?><?php $_template->updateParentVariables(0);?><?php unset($_template);?>